﻿using System;
using System.Text;
using System.Windows.Forms;

namespace COB.SharePoint.Utilities.DeploymentWizard.UI
{
    class TextBoxUtil
    {
        public static void AppendLineAndScroll(TextBox ctl, string text)
        {
            AppendLine(ctl, text);
            ScrollToEnd(ctl);
        }
        public static void ScrollToEnd(TextBox ctl)
        {
            ctl.SelectionStart = ctl.SelectionLength;
            ctl.ScrollToCaret();
        }
        public static void AppendLine(TextBox ctl, string text)
        {
            if (ctl.TextLength > 0)
            {
                ctl.Text += Environment.NewLine;
            }
            text = NormalizeLines(text);
            ctl.AppendText(text);
        }
        public static string NormalizeLines(string text)
        {
            text = text.Replace("\r\n", "\b");
            text = text.Replace("\n", "\b");
            text = text.Replace("\r", "\b");
            text = text.Replace("\b", Environment.NewLine);
            return text;
        }
    }
}
